package nowercoder.basics.exce01;

import java.util.Arrays;

public class BubbleSort {
    public static void bubbleSort(int[] array){
        if (array == null || array.length <2) return;
        for (int i = array.length -1 ; i > 0 ; i--) {
            for (int j = 0; j < i; j++) {
                if (array[j] > array[j+1]){
                    swap(array,j,j+1);
                }
            }
        }
    }

    public static void swap(int[] arr,int i, int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public static void main(String[] args) {
        int[] ar = {1,3,2,5,3,6,2,78,34,99,23};
        bubbleSort(ar);
        System.out.println(Arrays.toString(ar));
    }
}
